



export const state = () => ({
  userInfo:{
    token:'',
    user:null
  },
  cityList:[],
  history:[],
  airinfo:{}
})

export const mutations={
  setUserInfo(state,data){
    state.userInfo = data
  },
  clearUserInfo(state){
    state.userInfo ={}
    state.history = []
  },
  setcityList(state,data){
    state.cityList = data
  },
  setHistory(state,data){
    state.history.map(x=>{
      if(x.departCode==data.departCode&&data.destCode==x.destCode&&data.departDate==x.departDate){
        return ;
      }else{
        state.history.unshift(data)
      }
    })
    
  },
  setAirinfo(state,data){
    state.setAirinfo = data
  }
}

export const actions={
  login(store,obj){
    return this.$axios({
      method:'POST',
      url:'/accounts/login',
      data:obj.data
    }).then(res=>{
      const data = res.data
      store.commit('setUserInfo',data)
      console.log(data)
      if(data){
        return data
      }
      
    })
    
  },
  getCityList(store,data){
    return this.$axios({
      url:'/airs/city',
      params:{name:data}
    }).then(res=>{
      const newData = res.data.data.map(x=>{
        return{
          ...x,
          value:x.name.replace('市','')
        }
      })
      store.commit('setcityList',newData)
        return newData
    })
  }
}